home *** CD-ROM | disk | FTP | other *** search
- Path: news.uni-jena.de!news
- From: mkt@isun04.inf.uni-jena.de (Tilo Koerbs)
- Newsgroups: comp.lang.c++
- Subject: Re: Possible VC 4.0 bug?
- Date: 1 Feb 1996 13:17:20 GMT
- Organization: Lehrstuhl fuer Rechnerarchitektur- und kommunikation, FSU Jena
- Message-ID: <4eqeh0$na8@fsuj01.rz.uni-jena.de>
- References: <4eor3o$d06@enterprise.turningpoint.com>
- Reply-To: mkt@isun04.inf.uni-jena.de
- NNTP-Posting-Host: isun07.inf.uni-jena.de
-
- In article d06@enterprise.turningpoint.com, sathan@cybercom.net (Stephen Athanas) writes:
- > When I compile and run the following code under MSVC 4.0, I get an access
- > violation on the delete:
- >
- > class foo {
- > public :
- > virtual ~foo( ) { printf( "In foo::~foo.\n" ) }
- > };
- >
- > main() {
- > foo* p = new foo[ 0 ];
- > delete [] p;
- > }
- >
- > Everything works fine, and the destructor is never called, if the destructor
- > is not virtual. <----------- DOES THIS MEAN: A VIRTUAL DESTRUCTOR IS CALLED?
- > Is this a problem with VC, or with my understanding of how a new of size zero
- > should work? Thanks.
-
- Of course, it is allowed to call new for an array of size zero.
- And the compiler should return a pointer to a unique memory location.
- (A second call to new for an array of zero size should give a pointer
- different from the other.)
- Deleting such a pointer using delete[] is exacty the right thing to do!
- And regardless of a virtual or nonvirtual destructor: Since with the new [0]
- is NO object created, delete cannot call a destructor! (for which object
- should the destructor be invoked??? There is no object!)
-
- Thats what the C++ standard says.
-
- The only problem I see is: you should test if new returns 0.
-
- Bye.
-
-
-